//
//  UIView+DKCornerRadius.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/17.
//

#import "UIView+DKCornerRadius.h"

@implementation UIView (DKCornerRadius)
//顶部左右圆角
- (void)makeCornerTopleftRight:(CGFloat)corner{
    UIBezierPath *dkBezierPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(corner, corner)];
    CAShapeLayer *dkLayer = [[CAShapeLayer alloc] init];
    dkLayer.frame = self.bounds;
    dkLayer.path = dkBezierPath.CGPath;
    self.layer.mask = dkLayer;
}

- (UINavigationController *)getTopViewController{
    UIViewController * vc = [UIApplication sharedApplication].keyWindow.rootViewController;
    //顶层控制器 可能是 UITabBarController的跟控制器
    if ([vc isKindOfClass:[UITabBarController class]]) {
        vc = ((UITabBarController*)vc).selectedViewController;
    }
    //顶层控制器 可能是 push出来的 或者是跟控制器
    if ([vc isKindOfClass:[UINavigationController class]]) {
        UINavigationController *nav = (UINavigationController *)vc;
        if (nav.visibleViewController) {
            vc = nav.visibleViewController;
        }else {
            vc = nav.topViewController;
        }
    }
    //顶层控制器 可能是 modal出来的
    if (vc.presentedViewController) {
        vc = vc.presentedViewController;
    }
    return vc;
}
@end
